const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let target,source;
rl.on("line", (line)=>{
    if(target === undefined) {
        target = line.trim().split("")

    } else {
        source = line.trim().split("")
        console.log(getResult(source,target))

        // clear
        target = source = undefined;
    }

})

/**
 *
 * @param source {string} 源串
 * @param target {string} 子序列
 * @return {number} 返回最后一个匹配的子序列首角标
 */
function getResult(source,target) {
    let index = target.length - 1
    for (let i = source.length - 1; i >= 0 ; i--) {
            if(source[i] === target[index]) {
                index--;
                if(index === -1) {
                    return i
                }
            }
    }
    return -1
}


